home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-serious-
/
misc
/
msqllib
/
example
/
simple
/
simple.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-06
|
2KB
|
93 lines
/*
msql.library simple example
©1998 Christophe Sollet (cfc@iname.com)
This simple example list existing database and tables on
a mSQL database engine.
Without argument, it will try to connect on localhost
*/
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/msql.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Library *MsqlBase;
int main(int argc, char *argv[])
{
struct MsqlConnection *co;
m_result *mre, *mre2;
m_row mro, mro2;
char *host;
if(argc>1)
{
if(!strcmp(argv[1], "?"))
{
printf("Usage: %s hostname\n", argv[0]);
exit(0);
}
host = argv[1];
} else host = NULL;
if(MsqlBase = OpenLibrary("msql.library", 3)) /* Open the library */
{
/* Before doing any msql operation, we need a valid MsqlConnection structure */
if(co = MsqlAllocConnection())
{
/* Now we'll attempt a connection on a local mSQL database engine */
if(MsqlConnect(co, host))
{
/* Gets current DB list */
mre = MsqlListDBs(co);
if(mre)
{
printf("DB(s):\n");
/* Now display DB list */
while(mro = MsqlFetchRow(mre))
{
printf("%s\n", *mro);
/* For each DB, list tables */
if(MsqlSelectDB(co, *mro) != -1)
{
if(mre2 = MsqlListTables(co))
{
printf("\tTable(s):\n");
// Now display table list
while(mro2 = MsqlFetchRow(mre2))
{
printf("\t%s\n", *mro2);
}
}
MsqlFreeResult(mre2);
}
else
{
printf("SelectDB failed\n");
printf("%s\n", MsqlGetErrMsg(co)); // Display err message
}
}
MsqlFreeResult(mre);
} else
{
printf("ListDBs failed\n");
printf("%s\n", MsqlGetErrMsg(co)); // Display err message
}
MsqlClose(co);
} else
{
printf("Connection failed\n");
printf("%s\n", MsqlGetErrMsg(co));
}
MsqlFreeConnection(co);
} else printf("Alloc failed\n");
CloseLibrary(MsqlBase);
} else printf("Open Libs failed\n");
}